﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Data;
public partial class administrator_uc_admin_a_leftmenu : WebPageSecurity
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadDataToDropDownList(DropdownParentID, 0);
        }
    }
    private void LoadDataToDropDownList(DropDownList cboName, int MenuID)
    {
        ListItem list = new ListItem();
        cboName.Items.Clear();
        cboName.Items.Add(list);
        list.Selected = true;
        list.Value = "0";
        list.Text = "---Chọn menu cha---";
        DataTable dtb = new CmsBLL().LeftMenu_GetTree(MenuID);
        if (dtb.Rows.Count > 0)
        {
            new CommonBLL().LoadDropDonwList(cboName, dtb, "_Title", "MenuID");
        }
    }
    protected void lbtAddNewItem_Click(object sender, EventArgs e)
    {
        try
        {
            new CmsBLL().LeftMenu_InsertItem(int.Parse("0" + DropdownParentID.SelectedValue), txtTitle.Text.Trim(), txtDescription.Text.Trim(), txtUrl.Text.Trim(), int.Parse("0" + rdTarget.SelectedValue), int.Parse("0" + txtSortIndex.Text.Trim()), int.Parse("0" + rdActive.SelectedValue));
            lblMessage.Text = "Thêm mới thành công!";
            LoadDataToDropDownList(DropdownParentID, 0);
            ResetForm();
        }
        catch (Exception ex)
        {
            lblMessage.Text = "ERROR! " + ex.Message.ToString();
        }
    }
    private void ResetForm()
    {
        DropdownParentID.SelectedValue = "0";
        txtTitle.Text = "";
        txtDescription.Text = "";
        txtUrl.Text = "";
        rdTarget.SelectedValue = "0";
        txtSortIndex.Text = "";
        rdActive.SelectedValue = "1";
        txtTitle.Focus();
    }
}